// 公司信息页
import { useState, useEffect } from "react";
import style from "./style.module.css";
import * as companyapi from "../../services/company.services";
import * as recruitapi from "../../services/recruit.services";
import { ICompany, IRecruit } from "../../types";
import { useParams } from "react-router-dom";
import CompanyNav from "../../components/CompanyNav";
import CompanyRecruitSearchItem from "../../components/CompanyRecruitSearchItem";

interface Params {
  id: string;
}

export default function CompanyInfo() {
  const [information, setInfomation] = useState<ICompany>();
  const [rows, setRows] = useState<IRecruit[]>([]);
  const params = useParams<Params>();

  useEffect(() => {
    const getData = async () => {
      let result = await recruitapi.RecruitLi(params.id);
      if (result.stat === "OK") {
        setRows(result.result);
      }
      const information = await companyapi.company(params.id);
      if (information.stat === "OK") {
        setInfomation(information.result);
      }
    };
    getData();
  }, [params.id]);

  return (
    <>
      <CompanyRecruitSearchItem />
      <CompanyNav company={information} number={rows.length} />
      <div className={style.introCompany}>
        <div>
          <div className={style.introSimple}>
            <h4 className={style.title}>公司简介</h4>
            <div className={style.simpleTxt}>{information?.describe}</div>
          </div>
        </div>
      </div>
    </>
  );
}
